import {Component} from 'react';
import {DragSourceConnector, DragSourceMonitor} from 'react-dnd';

import {IDragItem} from './IDragItem';

export default {
  source: {
    beginDrag(props: any, monitor: DragSourceMonitor, component: Component<any, any>): IDragItem {
      if (props.widget) {
        return {
          viewType: props.widget.viewType
        };
      }
      if (props.view) {
        return {
          view: props.view
        };
      }
    }
  },

  collect(connect: DragSourceConnector, monitor: DragSourceMonitor) {
    return {
      connectDragSource: connect.dragSource(),
      isDragging: monitor.isDragging()
    };
  }
};
